home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / perl5 / strict.z / strict
Encoding:
Text File  |  2002-10-03  |  3.2 KB  |  133 lines

  1.  
  2.  
  3.  
  4. ssssttttrrrriiiicccctttt((((3333))))                                                            ssssttttrrrriiiicccctttt((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      strict - Perl pragma to restrict unsafe constructs
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.          use strict;
  13.  
  14.          use strict "vars";
  15.          use strict "refs";
  16.          use strict "subs";
  17.  
  18.          use strict;
  19.          no strict "vars";
  20.  
  21.  
  22. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  23.      If no import list is supplied, all possible restrictions are assumed.
  24.      (This is the safest mode to operate in, but is sometimes too strict for
  25.      casual programming.)  Currently, there are three possible things to be
  26.      strict about:  "subs", "vars", and "refs".
  27.  
  28.      strict refs
  29.            This generates a runtime error if you use symbolic references (see
  30.            the _p_e_r_l_r_e_f manpage).
  31.  
  32.                use strict 'refs';
  33.                $ref = \$foo;
  34.                print $$ref;        # ok
  35.                $ref = "foo";
  36.                print $$ref;        # runtime error; normally ok
  37.  
  38.  
  39.      strict vars
  40.            This generates a compile-time error if you access a variable that
  41.            wasn't declared via use vars, localized via my() or wasn't fully
  42.            qualified.  Because this is to avoid variable suicide problems and
  43.            subtle dynamic scoping issues, a merely _l_o_c_a_l() variable isn't good
  44.            enough.  See the my entry in the _p_e_r_l_f_u_n_c manpage and the local
  45.            entry in the _p_e_r_l_f_u_n_c manpage.
  46.  
  47.                use strict 'vars';
  48.                $X::foo = 1;         # ok, fully qualified
  49.                my $foo = 10;        # ok, my() var
  50.                local $foo = 9;      # blows up
  51.  
  52.                package Cinna;
  53.                use vars qw/ $bar /;        # Declares $bar in current package
  54.                $bar = 'HgS';               # ok, global declared via pragma
  55.  
  56.            The _l_o_c_a_l() generated a compile-time error because you just touched
  57.            a global name without fully qualifying it.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ssssttttrrrriiiicccctttt((((3333))))                                                            ssssttttrrrriiiicccctttt((((3333))))
  71.  
  72.  
  73.  
  74.      strict subs
  75.            This disables the poetry optimization, generating a compile-time
  76.            error if you try to use a bareword identifier that's not a
  77.            subroutine, unless it appears in curly braces or on the left hand
  78.            side of the "=>" symbol.
  79.  
  80.                use strict 'subs';
  81.                $SIG{PIPE} = Plumber;       # blows up
  82.                $SIG{PIPE} = "Plumber";     # just fine: bareword in curlies always ok
  83.                $SIG{PIPE} = \&Plumber;     # preferred form
  84.  
  85.  
  86.      See the section on _P_r_a_g_m_a_t_i_c _M_o_d_u_l_e_s in the _p_e_r_l_m_o_d_l_i_b manpage.
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.